home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 3.4 KB | 99 lines | [TEXT/GEOL] |
- Item 9093721 8-Aug-90 18:00PDT
-
- From: AUST0334 AUDev - CRIA, Canberra, ACT,IDV
-
- To: MACAPP.TECH$ MacApp Technical
-
- Sub: MemoryMgrProblem
-
- Re: Memory Management Problems
-
- Dear Fellow MacAppers,
-
- Recently I have been experiencing a few run-time bugs with our MacApp
- application. Various pictures were being deleted when memory was tight etc.
- Upon reading the relevant documentation on memory management, the problem was
- clear. These pictures and other data structures were going into MacApp
- temporary memory because the allocation was being performed by toolbox routines
- such as OpenPicture. To fix the problem I wrote a couple of routines to copy
- the memory blocks in these data structures to MacApp permanent memory where
- they would not be deleted.
-
- Having done this, I found that the pictures were still being deleted
- (presumably by MacApp). All I end up with is a master pointer which contains a
- null indicating an EmptyHandle has been performed. Although this is happening
- when memory is tight, I want the program to complain/fail on lack of free
- memory rather than releasing permanent blocks to make room. It is almost like
- these blocks are still in temporary memory. Has anyone else had this problem?
- I was under the impression the only way to do delete chunks of permanent memory
- was to explicity purge the handle yourself.
-
- I have included the example case where I copy a PicHandle which should be in
- temporary memory into a block that should be in permanent memory:
-
- ----------------------------------------------------------------------------
- TSomeCommand.DoIt;
- begin
- dstPic := OpenPicture(dstRect);
- {make up picture here}
- ClosePicture;
- error := Temp2PermHandle(Handle(dstPic)); {never any errors}
- SELF.fPicture := dstPic; {fPicture is emptied when memory is tight}
- end;
- ----------------------------------------------------------------------------
-
- Now for the functions:
-
- ----------------------------------------------------------------------------
- function PermHandToHand (var h: Handle): OSErr;
- {functionally identical to HandToHand except returned handle is permanent}
- var
- newH: Handle;
- error: OSErr;
- begin
- error := noErr;
- if h^ = nil then
- error := nilHandleErr;
- if error = noErr then
- begin
- newH := NewPermHandle(GetHandleSize(h)); {allocate a perm block?}
- if newH = nil then
- error := memFullErr;
- if error = noErr then
- begin
- HLock(Handle(h));
- HLock(Handle(newH));
- BlockMove(Ptr(h^), Ptr(newH^), GetHandleSize(h)); {copy block data}
- HUnlock(Handle(h));
- HUnlock(Handle(newH));
- end;
- end;
- h := newH; {return newH in h}
- PermHandToHand := error;
- end;
- ----------------------------------------------------------------------------
-
- ----------------------------------------------------------------------------
- function Temp2PermHandle (var h: Handle): OSErr;
- {moves handle to permanent memory by copying and deleting original handle}
- var
- newH: Handle;
- error: OSErr;
- begin
- newH := h;
- error := PermHandToHand(newH); {get a permanent copy of h}
- DisposHandle(h); {get rid of h}
- h := newH; {give back newH for h}
- Temp2PermHandle := error;
- end;
- ----------------------------------------------------------------------------
-
- Martin Flanagan
- Techway Solutions
- Australia
-
- Phone +62 (06) 256 3415
- Fax +62 (06) 251 5059
- Link AUST0334
-
-